package com.w7vm.menuweb.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

import com.w7vm.menuweb.entity.PlanoSy;
import com.w7vm.menuweb.utility.ConstantesEJB;


@Stateless
public class PlanoDAO extends GenericDAO<PlanoSy> {
	
	ConstantesEJB constEJB = new ConstantesEJB();
	
	@PersistenceContext
	private EntityManager em;
	
	public PlanoDAO() {
		super(PlanoSy.class);
		// TODO Auto-generated constructor stub
	}
	
	
	public List<PlanoSy> findPlanoByAll(){
		System.out.println("[EJB-PLANO][findPlanoByAll] :");
		return super.findByAll(PlanoSy.FIND_PLANO_BY_ALL);
	}

	public PlanoSy updateDadosPlano(PlanoSy planoEntity){
		System.out.println("[IAM-EJB][updateDadosPlano] :"+ planoEntity.getIdPlanoSys());
		PlanoSy plano = new PlanoSy();
		try{
			plano = super.update(planoEntity); 
			return plano;
		}catch (NoResultException e){
			System.err.println(e.getMessage());
			return plano;
		}
	}
	
	public int savePlano(PlanoSy planoEntity){
		System.out.println("[IAM-EJB][savePlano] :"+ planoEntity.getIdPlanoSys());
		try{
			em.persist(planoEntity);
			em.flush();
			return planoEntity.getIdPlanoSys();
		}catch (NoResultException e){
			System.err.println(e.getMessage());
			return 0;
		}
	}
}
